package pl.squeaky.mvc.generator;

import java.util.ArrayList;

import org.eclipse.php.internal.core.ast.nodes.AST;
import org.eclipse.php.internal.core.ast.nodes.ClassDeclaration;
import org.eclipse.php.internal.core.ast.nodes.FormalParameter;
import org.eclipse.php.internal.core.ast.nodes.FunctionDeclaration;
import org.eclipse.php.internal.core.ast.nodes.Identifier;
import org.eclipse.php.internal.core.ast.nodes.MethodDeclaration;
import org.eclipse.php.internal.core.ast.nodes.BodyDeclaration.Modifier;

public class ClassGenerator extends PhpGenerator {
	public ClassGenerator(String name) {
		super();
		AST ast = program.getAST();
		
		ClassDeclaration declaration = ast.newClassDeclaration(ClassDeclaration.MODIFIER_NONE, name, "Dummy", new ArrayList<Identifier>(), ast.newBlock());
		declaration.setSuperClass(null);
		
		program.statements().add(declaration);
	}
	
	public void setSuperclass(String name) {
		AST ast = program.getAST();
		ClassDeclaration declaration = (ClassDeclaration)program.statements().get(0);
		
		declaration.setSuperClass(ast.newIdentifier(name));
	}
	
	public void addMethod(String name) {
		addMethod(Modifier.PUBLIC, name);
	}
	
	public void addMethod(int modifier, String name) {
		AST ast = program.getAST();
		
		FunctionDeclaration function = ast.newFunctionDeclaration(ast.newIdentifier(name), new ArrayList<FormalParameter>(), ast.newBlock(), false);
		MethodDeclaration method = ast.newMethodDeclaration(modifier, function);
		
		ClassDeclaration declaration = (ClassDeclaration)program.statements().get(0);
		
		declaration.getBody().statements().add(method);
	}
}
